package com.ruoyi.receipt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receipt.domain.ErpMaterialReceipt;
import com.ruoyi.receipt.service.IErpMaterialReceiptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产入库Controller
 * 
 * @author ruoyi
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/receipt/receipt")
public class ErpMaterialReceiptController extends BaseController
{
    @Autowired
    private IErpMaterialReceiptService erpMaterialReceiptService;

    /**
     * 查询生产入库列表
     */
    @PreAuthorize("@ss.hasPermi('receipt:receipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpMaterialReceipt erpMaterialReceipt)
    {
        startPage();
        List<ErpMaterialReceipt> list = erpMaterialReceiptService.selectErpMaterialReceiptList(erpMaterialReceipt);
        return getDataTable(list);
    }

    /**
     * 导出生产入库列表
     */
    @PreAuthorize("@ss.hasPermi('receipt:receipt:export')")
    @Log(title = "生产入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpMaterialReceipt erpMaterialReceipt)
    {
        List<ErpMaterialReceipt> list = erpMaterialReceiptService.selectErpMaterialReceiptList(erpMaterialReceipt);
        ExcelUtil<ErpMaterialReceipt> util = new ExcelUtil<ErpMaterialReceipt>(ErpMaterialReceipt.class);
        util.exportExcel(response, list, "生产入库数据");
    }

    /**
     * 获取生产入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('receipt:receipt:query')")
    @GetMapping(value = "/{receiptId}")
    public AjaxResult getInfo(@PathVariable("receiptId") Long receiptId)
    {
        return success(erpMaterialReceiptService.selectErpMaterialReceiptByReceiptId(receiptId));
    }

    /**
     * 新增生产入库
     */
    @PreAuthorize("@ss.hasPermi('receipt:receipt:add')")
    @Log(title = "生产入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpMaterialReceipt erpMaterialReceipt)
    {
        return toAjax(erpMaterialReceiptService.insertErpMaterialReceipt(erpMaterialReceipt));
    }

    /**
     * 修改生产入库
     */
    @PreAuthorize("@ss.hasPermi('receipt:receipt:edit')")
    @Log(title = "生产入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpMaterialReceipt erpMaterialReceipt)
    {
        return toAjax(erpMaterialReceiptService.updateErpMaterialReceipt(erpMaterialReceipt));
    }

    /**
     * 删除生产入库
     */
    @PreAuthorize("@ss.hasPermi('receipt:receipt:remove')")
    @Log(title = "生产入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receiptIds}")
    public AjaxResult remove(@PathVariable Long[] receiptIds)
    {
        return toAjax(erpMaterialReceiptService.deleteErpMaterialReceiptByReceiptIds(receiptIds));
    }
}
